//
//  KLAudioPlayer.m
//  HealthManage
//
//  Created by 陈华 on 2017/4/13.
//  Copyright © 2017年 kinglian. All rights reserved.
//

#import "KLAudioPlayer.h"
#import <AVFoundation/AVFoundation.h>

@interface KLAudioPlayer()
/**播放器*/
@property(nonatomic,strong) AVPlayer *player;

@end

@implementation KLAudioPlayer


#pragma mark - 单例
static id _instance;
+ (instancetype)shareInstance
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _instance = [[self alloc]init];
    });
    return _instance;
}


- (instancetype)init
{
    if (self = [super init]) {
        
        
        //初始化
        //初始化播放器的时候如下设置
        UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
        AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory);
        UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
        AudioSessionSetProperty(kAudioSessionProperty_OverrideAudioRoute, sizeof(audioRouteOverride), &audioRouteOverride);
        
        AVAudioSession *audioSession = [AVAudioSession sharedInstance];
        //默认情况下扬声器播放
        [audioSession setCategory:AVAudioSessionCategoryPlayback error:nil];
        [audioSession setActive:YES error:nil];
        
        
    }
    return self;
}

@end
